home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / ext / IC / InternetConfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-08  |  4.7 KB  |  228 lines  |  [TEXT/MPS ]

  1. /* $Header: tyrathect:Development:Perl::RCS:missing.c,v 1.2 1994/05/04 02:12:43 neeri Exp $
  2.  *
  3.  *    Copyright (c) 1995 Matthias Neeracher
  4.  *
  5.  *    You may distribute under the terms of the Perl Artistic License,
  6.  *    as specified in the README file.
  7.  *
  8.  * $Log: missing.c,v $
  9.  */
  10.  
  11. #include "EXTERN.h"
  12. #include "perl.h"
  13. #include "XSUB.h"
  14. #include <ICAPI.h>
  15.  
  16. typedef ICInstance InternetConfig;
  17.  
  18. /* This prevents nested InternetConfig iterators. So what */
  19.  
  20. static int ICIter = 0;
  21.  
  22. XS(XS_InternetConfig_IC_TIEHASH)
  23. {
  24.     dXSARGS;
  25.     if (items != 1) {
  26.     croak("Usage: InternetConfig::TIEHASH(dbtype)");
  27.     }
  28.     {
  29.     char *    dbtype = (char *)SvPV(ST(0),na);
  30.     {
  31.             InternetConfig    ic;
  32.             ST(0) = sv_newmortal();
  33.             if (!ICStart(&ic, 'McPL')) {
  34.         sv_setref_pv(ST(0), "InternetConfig", (void*)ic);
  35.         ICFindConfigFile(ic, 0, nil);
  36.         }
  37.         }
  38.     }
  39.     XSRETURN(1);
  40. }
  41.  
  42. XS(XS_InternetConfig_IC_DESTROY)
  43. {
  44.     dXSARGS;
  45.     if (items != 1) {
  46.     croak("Usage: InternetConfig::DESTROY(ic)");
  47.     }
  48.     {
  49.     InternetConfig    ic;
  50.  
  51.     if (SvROK(ST(0))) {
  52.         IV tmp = SvIV((SV*)SvRV(ST(0)));
  53.         ic = (InternetConfig) tmp;
  54.     }
  55.     else
  56.         croak("ic is not a reference");
  57.     ICStop(ic);
  58.     }
  59.     XSRETURN(1);
  60. }
  61.  
  62. XS(XS_InternetConfig_IC_FETCH)
  63. {
  64.     dXSARGS;
  65.     if (items != 2) {
  66.     croak("Usage: InternetConfig::FETCH(ic, key)");
  67.     }
  68.     {
  69.     InternetConfig    ic;
  70.     Str255    key;
  71.  
  72.     if (sv_isa(ST(0), "InternetConfig")) {
  73.         IV tmp = SvIV((SV*)SvRV(ST(0)));
  74.         ic = (InternetConfig) tmp;
  75.     }
  76.     else
  77.         croak("ic is not of type InternetConfig");
  78.  
  79.     CopyC2PStr(SvPVX(ST(1)), key);
  80.     {
  81.         ICAttr    attr;
  82.         long    size;
  83.         
  84.             ST(0) = sv_newmortal();
  85.         switch (ICGetPref(ic, key, &attr, nil, &size)) {
  86.         case icTruncatedErr:
  87.         case 0:
  88.             ICGetPref(ic, key, &attr, sv_grow(ST(0), size + 1), &size);
  89.             SvCUR(ST(0)) = size;
  90.             *SvEND(ST(0)) = '\0';
  91.             (void)SvPOK_only(ST(0));        /* validate pointer */
  92.         break;
  93.         }
  94.         ICEnd(ic);
  95.     }
  96.     }
  97.     XSRETURN(1);
  98. }
  99.  
  100. XS(XS_InternetConfig_IC_STORE)
  101. {
  102.     dXSARGS;
  103.     if (items != 4) {
  104.     croak("Usage: InternetConfig::STORE(ic, key, value, flags)");
  105.     }
  106.     {
  107.     InternetConfig    ic;
  108.     Str255    key;
  109.     char *    value = (char *)SvPV(ST(2),na);
  110.     int    flags = (int)SvIV(ST(3));
  111.  
  112.     if (sv_isa(ST(0), "InternetConfig")) {
  113.         IV tmp = SvIV((SV*)SvRV(ST(0)));
  114.         ic = (InternetConfig) tmp;
  115.     }
  116.     else
  117.         croak("ic is not of type InternetConfig");
  118.  
  119.     CopyC2PStr(SvPVX(ST(1)), key);
  120.     {
  121.         ICSetPref(ic, key, 0, SvPVX(ST(2)), SvCUR(ST(2)));
  122.         ICEnd(ic);        
  123.     }
  124.     }
  125.     XSRETURN(1);
  126. }
  127.  
  128. XS(XS_InternetConfig_IC_DELETE)
  129. {
  130.     dXSARGS;
  131.     if (items != 2) {
  132.     croak("Usage: InternetConfig::DELETE(ic, key)");
  133.     }
  134.     {
  135.     InternetConfig    ic;
  136.     Str255    key;
  137.  
  138.     if (sv_isa(ST(0), "InternetConfig")) {
  139.         IV tmp = SvIV((SV*)SvRV(ST(0)));
  140.         ic = (InternetConfig) tmp;
  141.     }
  142.     else
  143.         croak("ic is not of type InternetConfig");
  144.  
  145.     CopyC2PStr(SvPVX(ST(1)), key);
  146.     {
  147.         ICBegin(ic, icReadWritePerm);
  148.         ICDeletePref(ic, key);
  149.         ICEnd(ic);        
  150.     }
  151.     }
  152.     XSRETURN(1);
  153. }
  154.  
  155. XS(XS_InternetConfig_IC_FIRSTKEY)
  156. {
  157.     dXSARGS;
  158.     if (items != 1) {
  159.     croak("Usage: InternetConfig::FIRSTKEY(ic)");
  160.     }
  161.     {
  162.     InternetConfig    ic;
  163.  
  164.     if (sv_isa(ST(0), "InternetConfig")) {
  165.         IV tmp = SvIV((SV*)SvRV(ST(0)));
  166.         ic = (InternetConfig) tmp;
  167.     }
  168.     else
  169.         croak("ic is not of type InternetConfig");
  170.     {
  171.         Str255 key;
  172.         
  173.         ICBegin(ic, icReadOnlyPerm);
  174.             ST(0) = sv_newmortal();
  175.         if (!ICGetIndPref(ic, ICIter = 1, key))
  176.         sv_setpvn(ST(0), ((char *) key) + 1, key[0]);
  177.         ICEnd(ic);
  178.     }
  179.     }
  180.     XSRETURN(1);
  181. }
  182.  
  183. XS(XS_InternetConfig_IC_NEXTKEY)
  184. {
  185.     dXSARGS;
  186.     if (items != 2) {
  187.     croak("Usage: InternetConfig::NEXTKEY(ic, key)");
  188.     }
  189.     {
  190.     InternetConfig    ic;
  191.     Str255    key;
  192.     char *    RETVAL;
  193.  
  194.     if (sv_isa(ST(0), "InternetConfig")) {
  195.         IV tmp = SvIV((SV*)SvRV(ST(0)));
  196.         ic = (InternetConfig) tmp;
  197.     }
  198.     else
  199.         croak("ic is not of type InternetConfig");
  200.  
  201.     CopyC2PStr(SvPVX(ST(1)), key);
  202.     {
  203.             ST(0) = sv_newmortal();
  204.         ICBegin(ic, icReadOnlyPerm);
  205.         if (!ICGetIndPref(ic, ++ICIter, key))
  206.         sv_setpvn(ST(0), ((char *) key) + 1, key[0]);
  207.         ICEnd(ic);
  208.     }
  209.     }
  210.     XSRETURN(1);
  211. }
  212.  
  213. XS(boot_InternetConfig)
  214. {
  215.     dXSARGS;
  216.     char* file = __FILE__;
  217.  
  218.     newXS("InternetConfig::TIEHASH", XS_InternetConfig_IC_TIEHASH, file);
  219.     newXS("InternetConfig::DESTROY", XS_InternetConfig_IC_DESTROY, file);
  220.     newXS("InternetConfig::FETCH", XS_InternetConfig_IC_FETCH, file);
  221.     newXS("InternetConfig::STORE", XS_InternetConfig_IC_STORE, file);
  222.     newXS("InternetConfig::DELETE", XS_InternetConfig_IC_DELETE, file);
  223.     newXS("InternetConfig::FIRSTKEY", XS_InternetConfig_IC_FIRSTKEY, file);
  224.     newXS("InternetConfig::NEXTKEY", XS_InternetConfig_IC_NEXTKEY, file);
  225.     ST(0) = &sv_yes;
  226.     XSRETURN(1);
  227. }
  228.